package shooter;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

/**
 * main
 * @author ulfgur
 */
public class Main extends SimpleApplication
{
    //manages the GUI
    public static NiftyManager mainNifty;
    //manages the game world/stage thingy
    public static WorldAppState world;
    //manages the cannon modification interface
    public static CannonAppState cannonMods;
    
    
    //start point
    public static void main(String[] args)
    {
        Main app = new Main();
        app.start();
    }
    
    /**
     * initialise
     */
    @Override
    public void simpleInitApp()
    {
        //create the nifty
        mainNifty = new NiftyManager(this);
        //create the world
        world= new WorldAppState(this);
        //attach the world
        getStateManager().attach(world);
        world.setEnabled(true);
        
        cannonMods = new CannonAppState(this);
        getStateManager().attach(cannonMods);
        cannonMods.setEnabled(false);
        //TODO: add functionality for
        //attaching and detaching nifty
        
        initKeys();
    }
    
    
    
    /**
     * initialises keys.
     * Note that this just
     * sets them up, doesn't 
     * actually bind them.
     */
    private void initKeys()
    {
          //TODO: figure out how to map oh, say, the RMB to cam movements.
            // You can map one or several inputs to one named action
            inputManager.addMapping("CannonEdit",  new KeyTrigger(KeyInput.KEY_L));
            
            enableInterfaceKeys();
      }
    
    
    /**
     * enables interface keys
     */
    public void enableInterfaceKeys()
    {
        inputManager.addListener(interfaceListener,"CannonEdit");
    }
    
      /**
       * responds to input
       */
      public ActionListener interfaceListener = new ActionListener()
      {
            public void onAction(String name, boolean keyPressed, float tpf)
            {
                if (name.equals("CannonEdit") && keyPressed)
                {
                    world.setEnabled(!world.isEnabled());
                    cannonMods.setEnabled(!cannonMods.isEnabled());
                    if(cannonMods.isEnabled())
                    {
                        cannonMods.setSnail(world.getPlayer());
                    }
                }
            }
      };
    
    @Override
    public void simpleUpdate(float tpf)
    {
        
    }
    
    @Override
    public void simpleRender(RenderManager rm) 
    {
        
    }
}
